package cn.szzsi.common.model.zshop;

import cn.szzsi.core.kit.CommonUtil;
import com.jfinal.kit.StrKit;

import java.util.Date;

/**
 * 企业相关信息业务类
 * Created by admin on 2017/6/21.
 */
public class CompanyInfoService {
    public static final CompanyInfoService cis=new CompanyInfoService();

    /**
     * 保存企业信息
     * @param phone 手机号码
     * @param brandName 品牌名称
     * @param personInCharge 企业负责人
     * @param categories 所属行业
     *@param categories 企业编号
     */
    public void saveInfo(String phone,String brandName,String personInCharge,String categories,String status,String shopId,String weChat,String qq,String product){
        CompanyInfo co=new CompanyInfo().use(CommonUtil.ZSHOP);
        co.setId(StrKit.getRandomUUID());
        co.setPhone(phone);
        co.setBrandName(brandName);
        co.setPersonInCharge(personInCharge);
        co.setCategories(categories);
        co.setStatus(status);
        co.setShopId(shopId);
        co.setWeChat(weChat);
        co.setQq(qq);
        co.setProduct(product);
        co.setCreateDate(new Date());
        //co.setUserId(SerialNumberUtil.buildCompanyNum());
        co.save();
    }


    /**
     *
     * @param company_name 公司名称
     * @param business_licence_code 营业执照注册号
     * @param business_licence_img 营业执照扫描件
     * @param email 邮箱
     * @param personInCharge 负责人
     * @param phone 手机号
     *
     * @param status
     * @param brandName
     * @param brandLogo
     * @param categories
     */
    public void updateInfo(CompanyInfo ci,String company_name,String business_licence_code,String business_licence_img,String email,String personInCharge,String phone,String status,String brandName,String brandLogo,String categories,String imgName,String product){
        ci.setCompanyName(company_name);
        ci.setBusinessLicenceCode(business_licence_code);
        ci.setBusinessLicenceImg(business_licence_img);
        ci.setEmail(email);
        ci.setPersonInCharge(personInCharge);
        ci.setPhone(phone);
        ci.setStatus(status);
        ci.setBrandName(brandName);
        ci.setBrandLogo(brandLogo);
        ci.setCategories(categories);
        ci.setImgName(imgName);
        ci.setProduct(product);
        ci.update();
    }

    /**
     *  超级管理员添加商户
     * @param company_name
     * @param business_licence_code
     * @param business_licence_img
     * @param phone
     * @param email
     * @param brandName
     * @param personInCharge
     * @param categories
     * @param status
     * @param shopId
     */
    public void sysSaveInfo(String company_name,String business_licence_code,String business_licence_img,String phone,String email,String brandName,String personInCharge,String categories,String status,String shopId,String brandLogo){
        CompanyInfo ci=new CompanyInfo();
        ci.setId(StrKit.getRandomUUID());
        ci.setCompanyName(company_name);
        ci.setBusinessLicenceCode(business_licence_code);
        ci.setBusinessLicenceImg(business_licence_img);
        ci.setPhone(phone);
        ci.setEmail(email);
        ci.setBrandName(brandName);
        ci.setPersonInCharge(personInCharge);
        ci.setCategories(categories);
        ci.setStatus(status);
        ci.setShopId(shopId);
        ci.setBrandLogo(brandLogo);
        ci.setCreateDate(new Date());
        //ci.setUserId(SerialNumberUtil.buildCompanyNum());
        ci.save();
    }

    /**
     *  超级管理员修改商户信息
     * @param company_name
     * @param business_licence_code
     * @param business_licence_img
     * @param phone
     * @param email
     * @param brandName
     * @param personInCharge
     * @param categories
     * @param shopId
     */
    public void sysUpdateInfo(String company_name,String business_licence_code,String business_licence_img,String phone,String email,String brandName,String personInCharge,String categories,String shopId,String brandLogo){
        CompanyInfo co=CompanyInfo.dao.getByShopId(shopId);
        co.setCompanyName(company_name);
        co.setBusinessLicenceCode(business_licence_code);
        co.setBusinessLicenceImg(business_licence_img);
        co.setPhone(phone);
        co.setEmail(email);
        co.setBrandName(brandName);
        co.setPersonInCharge(personInCharge);
        co.setCategories(categories);
        co.setBrandLogo(brandLogo);
        co.update();
    }

    /**
     * 检测是否存在手机号
     * @param phone
     * @param id
     * @return
     */
    public boolean isExistByPhone(String phone,String id){
        String sql="select * from sys_company_info where phone='"+phone+"'";
        if(StrKit.notBlank(id)){
            sql+=" and shopId!='"+id+"'";
        }
        CompanyInfo ci=CompanyInfo.dao.findFirst(sql);
        if(ci!=null){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 检测是否存在邮箱
     * @param email
     * @param id
     * @return
     */
    public boolean isExistByEmail(String email,String id){
        String sql="select * from sys_company_info where email='"+email+"'";
        if(StrKit.notBlank(id)){
            sql+=" and shopId!='"+id+"'";
        }
        CompanyInfo ci=CompanyInfo.dao.findFirst(sql);
        if(ci!=null){
            return true;
        }else{
            return false;
        }
    }
}






















